﻿@*YoursLC有源低代码 Create:admin 2023-07-04 14:31:20 添加或编辑-此文件放置于Views/WarehousingOfGoods /中*@

@using Think9.Models;
@*@model Think9.Models.WarehousingOfGoodsModel;*@
@{ ViewBag.Title = "Add";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

@*货品入库 ---根据表单设计生成*@
<style>
	/* 防止table的下拉列表被隐藏*/
	.layui-table-cell {
		overflow: visible;
	}
	.layui-table-box {
		overflow: visible;
	}
	.layui-table-body {
		overflow: visible; /* 与手机端冲突 */
	}
	/* 设置下拉框的高度与表格单元相同 */
	td .layui-form-select {
		margin-top: -3px;
		margin-left: -7px;
		margin-right: -7px;
	}
	.layui-table-view .layui-table th {
		overflow: hidden;
	}
</style>
<form class="layui-form layui-form-pane" lay-filter="formUser">
<input style="display:none" id="_isDebug" value="debug">@*debug为调试；release为发布*@
<input style="display:none" id="_listid" value="@ViewBag.ListId">
<input style="display:none" id="_plit" value="@ViewBag.Split">@*多选框字符分割*@
<input style="display:none" id="_frm" value="@ViewBag.Frm">@*从哪里跳转来的?默认list*@
<input style="display:none" id="_type" value="@ViewBag.Type">@*add或edit*@
<input style="display:none" id="_userid" value="@ViewBag.UserId">@*用户id*@
<input style="display:none" id="_attachmentId">@*附件id*@
<input style="display:none" id="_fwid" value="@ViewBag.FId">@*当前流程编码*@
<input style="display:none" id="prc_id" value="@ViewBag.PrcId">@*当前流程步骤id*@
<input style="display:none" id="prc_no" value="@ViewBag.PrcNo">@*当前流程步骤编码*@
@*弹出选择时页面间传递数据*@
<input style="display:none" id="pu_value">@*弹出选择时使用-弹出页面选择的值*@
<input style="display:none" id="pu_tbid">@*弹出选择时使用-触发弹出页面的表id，_main或子表编码*@
<input style="display:none" id="pu_indexid">@*弹出选择时使用-触发弹出页面的指标编码*@
<input style="display:none" id="pu_rowid">@*弹出选择时使用-子表弹出，对应tableid 哪一行*@
<input style="display:none" id="pu_column">@*弹出选择时使用-子表弹出，第几列*@
<div class="layui-form">
 <div class="layui-form-item"  style="text-align: right;">
	<div class="layui-btn-container">
			@*<a href="" target="_blank" id="print" class="layui-btn">打印</a>*@
			<button type="button" class="layui-btn" id="att">附件</button>
			<button type="button" class="layui-btn" lay-submit lay-filter="edit" id="edit">保存</button>
			@*<button type="button" class="layui-btn" lay-submit lay-filter="next"  id="next">转交</button>*@
			@*<button type="button" class="layui-btn" lay-submit lay-filter="finish" id="finish">结束</button>*@
	 </div>
  </div>

<div class="layui-form-item">
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">入库单号</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input type='text' name='inRKDH' id='inRKDH' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='请输入入库单号'  >
			</div>
		</div>
	</div>
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">入库日期</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input  name='inRKRQ' id='inRKRQ' class='layui-input' autocomplete='off'  onClick="WdatePicker({ el: this,dateFmt: 'yyyy-MM-dd'})" placeholder='yyyy-MM-dd'   lay-verify='required|date'   >
			</div>
		</div>
	</div>
</div>
<div class="layui-form-item">
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">入库类型</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<select id="inRKLX" name="inRKLX"  lay-filter = "inRKLX"   lay-verify='required'   >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inRKLX"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
			</div>
		</div>
	</div>
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">仓库</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<select id="inCK" name="inCK"  lay-filter = "inCK"   lay-verify='required'   >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inCK"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
			</div>
		</div>
	</div>
</div>
<div class="layui-form-item">
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">制单人</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input type='text' name='inZDR' id='inZDR' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='请输入制单人'  >
			</div>
		</div>
	</div>
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label required"  style="width:110px;">相关单位</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<select id="inXGDW" name="inXGDW"  lay-filter = "inXGDW"   lay-verify='required'   >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inXGDW"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
			</div>
		</div>
	</div>
</div>
<div class="layui-form-item">
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label"  style="width:110px;">金额</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input type='text' name='inJE' id='inJE' autocomplete='off' class='layui-input'  maxlength='15'    lay-verify='number'  placeholder='自动计算'  >
			</div>
		</div>
	</div>
	<div class="layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label"  style="width:110px;"><i class="layui-icon layui-icon-about" lay-tips="选择采购单号后自动读取采购明细" data-offset="4"></i>采购单号</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input type='text' name='inCGDH' id='inCGDH' autocomplete='off' class='layui-input'  maxlength='30'     placeholder='选择采购单号后自动读取采购明细'  >
			</div>
		</div>
	</div>
</div>
		<div class="layui-form-item">
			<label class="layui-form-label"  style="width:110px;">备注</label>
			<div class="layui-input-block"  style="margin-left:110px;">
				<input type='text' name='inBZ' id='inBZ' autocomplete='off' class='layui-input'  maxlength='200'     placeholder='请输入备注'  >
			</div>
		</div>
		<div class="layui-table-box" id="div_tb_WarehousingDetails">
			<table class="layui-hide" id="tb_WarehousingDetails" lay-filter="tableFilter"> </table></div>
</div>

</form>
<script>
	layui.config({
		base: '/self_js/'  /*自定义的js 在wwwroot/self_js文件夹中*/
	});
	layui.use(["form", "exLayer", "element", "exUtils",  "table", "WarehousingOfGoods"], function () {
		let form = layui.form;
		let layer = layui.layer;
		let table = layui.table;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let element = layui.element;
		let myJS = layui.WarehousingOfGoods;
		let $ = layui.$;

		form.render();
		getFormVal();//控件赋值-复选框和图片

		//Tab选项  
		element.on('tab(tabDemo)', function (data) {
        });
		//赋值--不包括多选框和图片
		form.val("formUser", {
			"inRKDH": "@Model.inRKDH"
			,"inRKRQ": showDate("@Model.inRKRQ")
			,"inRKLX": "@Model.inRKLX"
			,"inCK": "@Model.inCK"
			,"inZDR": "@Model.inZDR"
			,"inXGDW": "@Model.inXGDW"
			,"inJE": "@Model.inJE"
			,"inSHZT": "@Model.inSHZT"
			,"inCGDH": "@Model.inCGDH"
			,"inBZ": "@Model.inBZ"
		});
		//自定义控件赋值，用于多选框和图片的显示等
		function getFormVal() {


		}
		$('#inCGDH').on('click', function () {
			exLayer.open('选择采购单号', '/_TB/PopUpPage?tbid=_main&indexid=inCGDH&id=_n&from=add' + "&fwid=" + $("#_fwid").val(), '100%', '100%', '0px', '0px', null, null);
		});




		$('#att').on('click', function () {
			exLayer.open('附件上传', '/Com/FileManage/Attachment?fwid=' + $('#_fwid').val() + '&listid=' + $('#_listid').val() + '&prcid=' + $('#prc_id').val() + '&userid=' + $('#_userid').val() + '&attid=' + $('#_attachmentId').val(), '100%', '100%', '0px', '0px', null, null);
		});
		//点击保存按钮
		form.on("submit(edit)", function (data) {
			var _gridList = myJS.foreachGridTable();//遍历子表取数，在自定义js中定义
			exUtils.ajax('/_TB/SaveData', 'post', {
				model: data.field, 'gridlist': _gridList, listid: $('#_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val(), fwid: $('#_fwid').val(), json: JSON.stringify(data.field, null, 4) }, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
				if ($('#_frm').val() == 'list') {
					//从list页面跳转需刷新列表
					$(window.parent.document).find('#search').click();
				}
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			});
		}).fail(function (error) {
			console.log(error);
		});
			return false;
		});


			
		let tb_WarehousingDetails = table.render({
			elem: "#tb_WarehousingDetails",
			url: "/_TB/GetGridList?tbid=tb_WarehousingDetails"+"&listid=" + $('#_listid').val() + "&from=" + $('#_type').val() + "&fwid=" + $('#_fwid').val(),
			page: false,
			cols: [[
				@*flag与Vn(n为大于等于1的整数)之间不能手动插入或删除列，不能更改次序，否则会有错误*@
				{ field: "flag",  hide: true }
				,{ field: "v1", title: "编码", width: 130, templet: '#tb_WarehousingDetailsv1' }
				,{ field: "v2", title: "名称<span style='color: red'>*</span>", width: 130, templet: '#tb_WarehousingDetailsv2' }
				,{ field: "v3", title: "规格", width: 130, templet: '#tb_WarehousingDetailsv3' }
				,{ field: "v4", title: "单位", width: 130, templet: '#tb_WarehousingDetailsv4' }
				,{ field: "v5", title: "单价", width: 130, templet: '#tb_WarehousingDetailsv5' }
				,{ field: "v6", title: "数量", width: 130, templet: '#tb_WarehousingDetailsv6' }
				,{ field: "v7", title: "金额", width: 130, templet: '#tb_WarehousingDetailsv7' }
				,{ field: "v8", title: "备注", width: 180, templet: '#tb_WarehousingDetailsv8' }
				,{ title: "", align: "left", templet: "#addordelitem" }
			]],
			done: function (res, curr, count) {
				//手机给div设定宽度，要不表头显示不全
				if ($(window).width() < 768) {
					//$('th').hide();//表头隐藏
					$('#div_tb_WarehousingDetails').css({ 'width': '1270'});
				}
				$('.layui-table .layui-table-cell > span').css({ 'font-weight': 'bold' });
				
				if (count == -1) {
					layer.msg(res.msg, { icon: 5, time: 20000, btn: ['关闭'] });//显示错误
				}
				
			}
		
		});

	   table.on("tool(tableFilter)", function (obj) {
		let data = obj.data;
		switch (obj.event) {
			case "addGrid":
				addGrid(data);
				break;
			case "delGrid":
				delGrid(data);
				break;
		 }
		});

		//子表添加一条数据，点击右侧添加按钮调用
		function addGrid(data) {
			var _controlsList = myJS.getControlValueList();//主表所有控件
            var _gridList = myJS.getFirstGridTable();//只取子表数据首行
			exUtils.ajax("/_TB/AddGrid", "post", { model: data.field, "list": _gridList, tbid: data.TbId, listid: $('#_listid').val(), fwid: $("#_fwid").val(), controlslist: _controlsList }, true).done(function (response) {
				$("#_listid").val(response.extra);
				tableRender(data.TbId);//子表数据刷新
			}).fail(function (error) {
				console.log(error);
			});
		}

		//子表删除一条数据，点击右侧删除按钮调用
		function delGrid(data) {
		    var _controlsList = myJS.getControlValueList();//主表所有控件
			exLayer.confirm("确定要删除吗？", function () {
				exUtils.ajax("/_TB/DelGrid", "post", { flag: data.flag, listid: data.ListId, fwid: $("#_fwid").val(), controlslist: _controlsList }, true).done(function (response) {
					tableRender(data.TbId);//子表数据刷新
					 exUtils.tableSuccessMsg('删除成功！');
				}).fail(function (error) {
					console.log(error);
				});
			})
		}

		//子表刷新
		function tableRender(tbid) {
			if (tbid == 'tb_WarehousingDetails' || tbid.indexOf('#tb_WarehousingDetails#') > -1) {
				tb_WarehousingDetails.reload({
					url: "/_TB/GetGridList?tbid=tb_WarehousingDetails" + "&listid=" + $('#_listid').val() + "&from=" + $('#_type').val() + "&fwid=" + $('#_fwid').val()
				});
			}
		}

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "_event":
                    break;

            }
        });

		//弹出页面关闭后为控件赋值并执行数据读取 无弹出页面可删除
		$("#pu_value").click(function () {
			myJS.getValueFromPopUp();//弹出页面关闭后，将选择的Value赋值给触发弹出页面的input，在自定义js中定义
			readValue();//执行数据读取，每个弹出都触发--可手动优化
		});

		//数据读取
		function readValue() {
			var _gridList = myJS.getCurrentGridTable($('#pu_tbid').val(), $('#pu_rowid').val());
            var _controlsList = myJS.getControlValueList();//主表所有控件ID和Value，在自定义js中定义

			exUtils.ajax("/_TB/AfterControlSelect", "post", { controlslist: _controlsList, "gridlist": _gridList, id: $('#pu_rowid').val(), tbid: $('#pu_tbid').val(), indexid: $('#pu_indexid').val(), value: $('#pu_value').val(), fwid: $('#_fwid').val(), listid: $('#_listid').val() }, true).done(function (response) {
				var lists = response.list;
				var _listid = response.extra;
                var _grid = response.extra2;
				if (_listid != "") {
                    $('#_listid').val(_listid)
                }
                if (lists != null) {
                    //console.log(lists);
                    myJS.setValueByList(lists);//使用后台返回的lists，为控件赋值，在自定义js中定义
				}
				if (_grid != "") {
                    tableRender(_grid);//子表数据刷新
				}

				form.render();//一定要加
			}).fail(function (error) {
				console.log(error);
			});

			return false;
		}

		//打印
        function setPrint() {
            $("#print").attr("href", "/_TB/Print?listid=" + $('#_listid').val() + "&type=pdf&fwid=" + $('#_fwid').val());
        }

		//消息提示
        $(document).on("mouseenter", "*[lay-tips]", function () {
            var remind = $(this).attr("lay-tips");
            var tips = $(this).data("offset") || 4;
            var color = $(this).data("color") || '#88858e';
            layer.tips(remind, this, {
                time: -1,
                tips: [tips, color],
                area: ['auto', 'auto'],
            });
        }).on("mouseleave", "*[lay-tips]", function () {
            layer.closeAll("tips");
        });

		$(document).ready(function () {
		    setPrint();//打印

			myJS.setFormButDisable("@ViewBag.DisableBut");//控制页面按钮状态
		    myJS.setStateByFlow($('#prc_no').val());//根据步骤编码设置控件disabled属性
			form.render('select');//要加上，否则下拉选择disabled设置无效

			if (layui.device().mobile) {
				//手机端
				$(".layui-btn").attr("class", "layui-btn layui-btn-sm");
            }
        });
	});
</script>
<!-- 添加或删除 排除了统计行 -->
<script type='text/html' id='addordelitem'>
    {{#  if(d.Id >= 0){ }}
    {{#  if(d.Id == 0){ }}
    <button type="button" class='layui-btn layui-btn-xs' title='添加数据' lay-event='addGrid' id='addGrid'><i class='fa fa-plus'></i></button>
    {{#  } else{ }}
    <button type="button" class='layui-btn layui-btn-danger layui-btn-xs' title='删除数据' lay-event='delGrid' id='delGrid'><i class='fa fa-minus'></i></button>
    {{#  } }}
    {{#  } }}
</script>
<!-- 编码 -->
<script type="text/html" id="tb_WarehousingDetailsv1">
	<input type='text' name='tb_WarehousingDetailsv1' value = '{{d.v1_Exa}}' autocomplete='off' class='layui-input'  maxlength='30' style='height:30px;'  placeholder='编码' {{d.v1_JS}} {{d.v1_Lock}}>
</script>
<!-- 名称 -->
<script type="text/html" id="tb_WarehousingDetailsv2">
	<input type='text' name='tb_WarehousingDetailsv2' value = '{{d.v2_Exa}}' autocomplete='off' class='layui-input'  maxlength='30' style='height:30px;'  placeholder='名称'  {{d.v2_Lock}}>
</script>
<!-- 规格 -->
<script type="text/html" id="tb_WarehousingDetailsv3">
	<input type='text' name='tb_WarehousingDetailsv3' value = '{{d.v3_Exa}}' autocomplete='off' class='layui-input'  maxlength='30' style='height:30px;'  placeholder='规格'  {{d.v3_Lock}}>
</script>
<!-- 单位 -->
<script type='text/html' id='tb_WarehousingDetailsv4'>
	<div class='layui-input-inline' style='width:100px;'>
		<select name={{'id_'+d.Id}} data-value={{d.v4}} lay-filter='tb_WarehousingDetails_v4' {{d.v4_Lock}}>
		<option value="">==请选择==</option>
		{{d.v4_Exa}}
		</select>
	</div>
</script>
<!-- 单价 -->
<script type="text/html" id="tb_WarehousingDetailsv5">
	<input type='text' name='tb_WarehousingDetailsv5' value = '{{d.v5_Exa}}' autocomplete='off' class='layui-input'  maxlength='15' style='height:30px;'  placeholder='单价'  {{d.v5_Lock}}>
</script>
<!-- 数量 -->
<script type="text/html" id="tb_WarehousingDetailsv6">
	<input type='text' name='tb_WarehousingDetailsv6' value = '{{d.v6_Exa}}' autocomplete='off' class='layui-input'  maxlength='15' style='height:30px;'  placeholder='数量'  {{d.v6_Lock}}>
</script>
<!-- 金额 -->
<script type="text/html" id="tb_WarehousingDetailsv7">
	<input type='text' name='tb_WarehousingDetailsv7' value = '{{d.v7_Exa}}' autocomplete='off' class='layui-input'  maxlength='15' style='height:30px;'  placeholder='¥'  {{d.v7_Lock}}>
</script>
<!-- 备注 -->
<script type="text/html" id="tb_WarehousingDetailsv8">
	<input type='text' name='tb_WarehousingDetailsv8' value = '{{d.v8_Exa}}' autocomplete='off' class='layui-input'  maxlength='100' style='height:30px;'  placeholder='备注'  {{d.v8_Lock}}>
</script>
<!-- 子表onclick调用 -->
<script>
	function PopUpPage(tbid, indexid, id) {
		var url = '/_TB/PopUpPage?';
		PopSelectValue(tbid, indexid, id, url, document.getElementById("_fwid").value);
	}
	function PopUpImgUplaod(tbid, indexid, id, fname) {
		PopImgUplaod2(tbid, indexid, id, fname);
	}
</script>